import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, SetMetadata } from '@nestjs/common';
import { GuardService } from './guard.service';
import { CreateGuardDto } from './dto/create-guard.dto';
import { UpdateGuardDto } from './dto/update-guard.dto';
import { RoleGuard } from './role/role.guard';//局部用法
import { Role,ReqUrl } from './role/role.decorator';
import { ApiTags, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiBearerAuth } from '@nestjs/swagger';

@Controller('guard')
@ApiBearerAuth()//jwt验证
@ApiTags('守卫接口')
@UseGuards(RoleGuard)
export class GuardController {
  constructor(private readonly guardService: GuardService) {}

  @Post()
  create(@Body() createGuardDto: CreateGuardDto) {
    return this.guardService.create(createGuardDto);
  }

  @Get()
  @ApiOperation({summary:'get接口',description:'描述XXXX'})
  // @SetMetadata('role',['admin'])
  @Role('admin')//自定义装饰器
  @ApiQuery({name:'page',description:'分页信息'})
  @ApiResponse({status:403,description:'小黑子我是403'})
  findAll(@ReqUrl("123") url:string) {
    console.log(url,'url');
    return this.guardService.findAll();
  }

  @Get(':id')
  @ApiParam({name:'id',description:'这是一个id',required:true,type:'string'})
  findOne(@Param('id') id: string) {
    return this.guardService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateGuardDto: UpdateGuardDto) {
    return this.guardService.update(+id, updateGuardDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.guardService.remove(+id);
  }
}
